const express = require(`express`);
const path = require("path");
const ejs = require("ejs");
const config = require("./config/default");
const router = require('./routes/index.js');
const routerfile = require('./routes/files.js');
const cors = require('cors');

const app = express();

// 获取静态路径
app.use(express.static(__dirname + '/views'));
app.use(express.static(__dirname + '/data'));

// 允许跨域访问
app.use(cors());

// 加入 html 视图
// app.set('views', path.join(__dirname, '/views'));
app.engine('html', ejs.__express);
app.set('view engine', 'html');

// 解析前端数据
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// 引入路由
app.use(router);
// 修改路由挂载路径
app.use('/', routerfile);


// 启动服务器，添加分号和右括号
app.listen(config.port,'0.0.0.0', () => {
    console.log(`我启动了端口${config.port}`);
});
